package com.lottery.service.pc28.lobbyService.impl;

import com.lottery.dao.pc28.lobbyDao.LotteryOddsDao;
import com.lottery.dao.pc28.lobbyDao.PlaywayinfoDao;
import com.lottery.dto.ResultDto;
import com.lottery.dto.SscOddsShow;
import com.lottery.entity.LotteryOdds;
import com.lottery.entity.Playwayinfo;
import com.lottery.service.pc28.InitData;
import com.lottery.service.pc28.lobbyService.LotteryOddsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class LotteryOddsServiceImpl implements LotteryOddsService {

    @Autowired
    private LotteryOddsDao lotteryOddsDao;

    @Autowired
    private PlaywayinfoDao playwayinfoDao;

    /**
     * 查询赔率表
     */
    @Override
    public ResultDto<LotteryOdds> selectLotteryOddsList() {
        ResultDto<LotteryOdds> result = new ResultDto<LotteryOdds>();
        try {
            List<LotteryOdds> lotteryOddsList = lotteryOddsDao.selectLotteryOddsList();
            result.setList(lotteryOddsList);
            result.setSuccess(true);
            result.setMessage("查询成功！");
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("查询失败！");
        }
        return result;
    }

    /**
     *
     */
    @Override
    public Map<String, List<SscOddsShow>> selectLotteryOddsSshow(int lotteryType) {
        Map<String, List<SscOddsShow>> map =null;
        if(lotteryType == 1){
             map = InitData.sscOddMap;
        }else if(lotteryType == 2){
            map = InitData.pc28OddMap;
        }

        return map;
    }




    /**
     * 修改赔率
     */
    @Override
    public ResultDto<LotteryOdds> updateLotteryOdds(LotteryOdds lotteryOdds) {
        ResultDto<LotteryOdds> result = new ResultDto<LotteryOdds>();
        if (lotteryOdds.getEachMoney() <= 0 || lotteryOdds.getOdds() <= 0) {
            result.setSuccess(false);
            result.setMessage("输入内容不能为0或负数!");
            return result;
        }
        try {
            // 修改赔率
            lotteryOddsDao.updateLotteryOdds(lotteryOdds);

            // 实例化玩法
            Playwayinfo playwayinfo = new Playwayinfo();
            playwayinfo.setPlaywayName(lotteryOdds.getPlaywayName());
            playwayinfo.setEachMoney(lotteryOdds.getEachMoney());
            // 修改每一注的金额
            playwayinfoDao.updatePlaywayinfo(playwayinfo);

            result.setSuccess(true);
            result.setMessage("修改成功！");
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("修改失败！");
        }
        return result;
    }

    /**
     * 查询比例分成
     */
    @Override
    public ResultDto<Double> selectLotteryOddsRatio() {
        ResultDto<Double> resultDto = new ResultDto<Double>();
        Double ratio = 0.0;
        try {
            ratio = lotteryOddsDao.selectLotteryOddsRatio();
            resultDto.setData(ratio);
            resultDto.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            resultDto.setSuccess(false);
        }
        return resultDto;
    }

    /**
     * 修改分成比例
     */
    @Override
    public ResultDto<Double> updateLotteryOddsRatio(Double ratio) {
        ResultDto<Double> resultDto = new ResultDto<Double>();
        try {
            if (ratio >= 0 && ratio < 1) {
                lotteryOddsDao.updateLotteryOddsRatio(ratio);
                resultDto.setSuccess(true);
                resultDto.setMessage("修改成功");
            } else {
                resultDto.setSuccess(false);
                resultDto.setMessage("请输入0~1之间的参数");
            }
        } catch (Exception e) {
            e.printStackTrace();
            resultDto.setSuccess(false);
            resultDto.setMessage("修改失败");
        }
        return resultDto;
    }

}
